import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 将一个二叉搜索树转化成双向链表
 * User: xwl
 * Date: 2023-06-04
 * Time: 21:41
 */

class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode(int val) {
        this.val = val;
    }

}


public class Test5 {
    public TreeNode Convert(TreeNode pRootOfTree) {
        ConvertChild(pRootOfTree);
        TreeNode head = pRootOfTree;
        while (head != null && head.left != null) {
            head = head.left;
        }
        return head;
    }

    TreeNode prev = null;

    public void ConvertChild(TreeNode pCur) {
        if (pCur == null) {
            return;
        }

        ConvertChild(pCur.left);
        pCur.left = prev;
        if (prev != null) {
            prev.right = pCur;
        }
        prev = pCur;
        ConvertChild(pCur.right);
    }


}
